<?php 
/**
 * [weliam] Copyright (c) 2016/3/26
 * 商城系统设置控制器
 */
defined('IN_IA') or exit('Access Denied');

load()->func('communication');
$ops = array('base','display','qr','ajax','copyright');
$op_names = array('系统设置');
foreach($ops as $key=>$value){
	permissions('do', 'ac', 'op', 'store', 'setting', $ops[$key], '订单', '参数设置', $op_names[$key]);
}
$op=$_GPC['op'];
$op = in_array($op, $ops) ? $op : 'display';
wl_load()->model('setting');
//权限控制
$tid=8166;
//
wl_load()->model('functions');
$checkfunction=checkfunc($tid);
$_W['page']['title'] = $checkfunction['name'];

if($op=='base')
{
	include wl_template('store/notice');
}
//截止
if ($op == 'display') {
	$_W['page']['title'] = '商城信息设置 - 系统管理';
	$set = setting_get_list();
	if(empty($set)){
		$settings = $this->module['config'];
	}else{
		$settings = array();
		foreach($set as$key=>$value){
			$settingarray= $value['value'];
			foreach($settingarray as $k=>$v){
				$settings[$k] = $v;
			}
		}
	}
	$functionlist=pdo_fetchall("select * from ".tablename('tg_function')." where type=1");
	$wechats=pdo_fetch("select * from ".tablename('account_wechats')." where uniacid=".$_W['uniacid']);
	foreach($functionlist as $key=>$value){
			$functionlist[$key]['status']=0;
			$functionlist[$key]['endtime']=0;
			$function_detail=pdo_fetch("select * from ".tablename('tg_function_detail')." where functionid=:functionid and  uniacid=:uniacid",array(':functionid'=>$value['id'],':uniacid'=>$_W['uniacid']));
			
			if(!empty($function_detail)&&$function_detail['endtime']>time())
			{
				$functionlist[$key]['status']=1;
				$functionlist[$key]['endtime']=$function_detail['endtime'];
			}
			if($wechats['tpl']==$value['id'])
			{
				$functionlist[$key]['status']=2;
			}
	}
//	wl_debug($settings);m_no_num_success
	if (checksubmit('submit')) {
		load()->func('file');
        
		$message = array(
				'm_bukuan'=>$_GPC['m_bukuan'],
				'm_result'=>$_GPC['m_result'],
			'm_daipay'=>$_GPC['m_daipay'],
			'pay_suc'=>$_GPC['pay_suc'],
            'm_pay'=>$_GPC['m_pay'],
            'm_tuan'=>$_GPC['m_tuan'],
			'l_suc'=>$_GPC['l_suc'],
            'l_tuan'=>$_GPC['l_tuan'],
			'm_nocash'=>$_GPC['m_nocash'],
            'm_cancle'=>$_GPC['m_cancle'],
            'm_ref'=>$_GPC['m_ref'],
			'm_no_num_success'=>$_GPC['m_no_num_success'],
			'm_hexiao'=>$_GPC['m_hexiao'],
            'm_send'=>$_GPC['m_send'],
			'm_buy'=>$_GPC['m_buy'],
			'm_change'=>$_GPC['m_change'],
			'm_feedback'=>$_GPC['m_feedback'],
			'm_service'=>$_GPC['m_service']
		);
		
		$pdomessage = array(
			'uniacid'=>$_W['uniacid'],
			'key'=>'message',
			'value'=>serialize($message)
		);
		

		$ifmessage = setting_get_by_name('message');
		
		
		if(!empty($ifmessage)){
			setting_update_by_params($pdomessage, array('key'=>'message','uniacid'=>$_W['uniacid']));
		}else{
			setting_insert($pdomessage);
		}
		
		message('更新设置成功！', web_url('store/notice/display'));
	}
	include wl_template('store/notice');
}
exit();

